package com.iefgames.cs.manager;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import com.iefgames.cs.pople.Pople;

public final class PopleManager {
	private static final Map<String, Pople> PopleMap = new HashMap<String, Pople>();
	
	public static void set(Pople pople) {
		PopleMap.put(pople.getUuid(), pople);
	}
	
	public static Pople get(String uuid) {
		return PopleMap.get(uuid);
	}
	
	public static boolean hasPople(String uuid) {
		return isOnline(uuid);
	}
	
	public static boolean isOnline(String uuid) {
		Pople p = get(uuid);
		if (p == null) {
			return false;
		}
		
		return p.isOnline();
	}
	
	public static void removePople(String uuid) {
		PopleMap.remove(uuid);
	}
	
	//TODO: 随机产生客服uuid
	public static String getRandomOnlineCsUuid() {
		Collection<Pople> poples =  PopleMap.values();
		for (Pople p : poples) {
			if (p.isCs()) {
				if (p.isOnline()) {
					return p.getUuid();
				}
			}
		}
		
		return null;
	}
}
